/**
 * 批量删除
 * @param idList idList
 * @param deleteApi deleteApi
 * @param callback callback
 */
export function useDeleteBatch(
  idList: Ref<string[]>,
  deleteApi: (idList: string[]) => Promise<any>,
  callback?: () => void,
) {
  function deleteBatch() {
    if (idList.value.length === 0) {
      Message({
        type: 'warning',
        message: '请选择要删除的数据',
      })
      return
    }
    ElMessageBox.confirm(
      `确定删除已选择的 ${idList.value.length} 条数据?`,
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    )
      .then(async () => {
        await deleteApi(idList.value)
        Message({
          type: 'success',
          message: '删除成功',
        })
        callback && callback()
      })
  }
  return [deleteBatch] as const
}
